package com.bilgeadam.javaweb.listener;

import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author Bora SAYINER
 * @since Dec 27, 2014 6:52:29 PM
 * @version 1.0
 */
public class ServletRequestHandler implements ServletRequestListener {

	@Override
	public void requestDestroyed(ServletRequestEvent sre) {

	}

	@Override
	public void requestInitialized(ServletRequestEvent sre) {
		ServletRequest servletRequest = sre.getServletRequest();
		HttpServletRequest request = (HttpServletRequest) servletRequest;
		if (!request.getRequestURI().endsWith(".css")) {
			ServletContext servletContext = sre.getServletContext();
			int count = (int) servletContext.getAttribute("count");
			count++;
			servletContext.setAttribute("count", count);
			System.out.println(count);
		}
	}

}
